<template>
  <div id="app">
    <h2>App根组件</h2>
    <hr />
    <button @click="comName = 'Left'">展示Left</button>
    <button @click="comName = 'Right'">展示Right</button>

    <div class="box">
      <!-- keep中include属性，包含要被缓存的组件，exclude属性排除不被缓存的组件，不要同时使用这两个属性 -->
      <keep-alive include="Left">
        <component :is="comName"></component>
      </keep-alive>
    </div>
  </div>
</template>


<script>
import Left from "./components/Left.vue";
import Right from "./components/Right.vue";

export default {
  name: "App",
  data() {
    return {
      comName: "Left",
    };
  },
  components: {
    Left,
    Right,
  },
};
</script>

<style lang="less">
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
